package ro.prjmanager.core.context;


import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;

/**
 * Map to wrap request scope attributes.
 *
 * @author Tacliciu Viorel
 */
public class RequestMap extends BaseHttpMap {

    private HttpServletRequest request;
   /**
    * Create a RquestMap from the request.
    * @param request the client http request
    */
    public RequestMap(HttpServletRequest request) {
        this.request = request;
    }
    /**
     * Return the name of the attributes form a request.
     * @return an <code>enumeration</code> with the names for the
     * request attributes
     */
    protected Enumeration getNames() {
        return request.getAttributeNames();
    }
    /**
     * Get the value of an request attribute
     * @param key the object name
     * @return the object value
     */
    protected Object getValue(Object key) {
        return request.getAttribute(String.valueOf(key));
    }
    /**
     * Put an object on request like an attribute.
     *
     * @param key the name of the objecte
     * @param value the object instance
     *
     */
    protected void putValue(Object key, Object value) {
        request.setAttribute(String.valueOf(key), value);
    }
    /**
     * Remove an object from request attributes.
     * @param key the object identifier
     */
    protected void removeValue(Object key) {
        request.removeAttribute(String.valueOf(key));
    }

}
